﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

using CSA.Lib;

namespace CSA.OptimalMonitoringNetwork
{
    [Serializable]
    public class CSOMNAntibody : CSAntibody
    {
        List<Int32> m_Data = new List<int>();

        #region Fields

        public override Object Genes
        {
            get
            {
                Object obj = (Object)m_Data;
                return obj;
            }
            set
            {
                m_Data = (List<Int32>)value;
                m_AntibodyLength = m_Data.Count;
            }
        }

        #endregion

        public CSOMNAntibody()
        {

        }

        public override void ClearGene()
        {
            m_Data.Clear();
            m_AntibodyLength = 0;
        }

        public override CSAntibody Clone()
        {
            CSOMNAntibody nNewAb = new CSOMNAntibody();
            nNewAb.Affinity = this.Affinity;
            nNewAb.ObjectiveValues = new List<double>(ObjectiveValues);
            nNewAb.Generation = this.Generation;
            List<Int32> nGenesData = new List<Int32>((List<Int32>)Genes);
            nNewAb.Genes = nGenesData;
            return nNewAb;
        }

        public override bool AddGene(Object nGeneValue)
        {
            try
            {
                if (nGeneValue is Int32)
                {
                    Int32 nValue = (Int32)nGeneValue;
                    m_Data.Add(nValue);
                    m_AntibodyLength += 1;
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch
            {
                return false;
            }
        }

        public override bool SetGene(Object nGeneValue, int nPos)
        {
            try
            {
                if (nGeneValue is Int32)
                {
                    Int32 nValue = (Int32)nGeneValue;
                    if (nPos > -1 && nPos < m_Data.Count)
                    {
                        m_Data[nPos] = nValue;
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            catch
            {
                return false;
            }
        }

        public override Object GetGene(int nPos)
        {
            try
            {
                if (nPos > -1 && nPos < m_Data.Count)
                {
                    Object obj = m_Data[nPos];
                    return obj;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return false;
            }
        }

        public override void Print()
        {
            String nGeneStr = "";
            for (int i = 0; i < m_Data.Count; i++)
            {
                nGeneStr += m_Data[i].ToString() + "-";
            }
        }
    }
}

